package com.foo.designpattern.flyweight.ComplexFlyweight;

/**
 * com.foo.designpattern.flyweight.ComplexFlyweight
 * Created with IntelliJ IDEA.
 * Created by jiang on 2016-05-24 9:54.
 *
 * @Description 具体享元(ConcreteFlyweight)角色
 * 具体享元角色：实现抽象享元角色所规定出的接口。如果有内蕴状态的话，必须为内蕴状态提供存储空间。
 */

public class ConcreteFlyweight implements Flyweight {

    private Character intrinsicState = null;

    /**
     * 构造函数：内蕴状态作为参数传入
     *
     * @param intrinsicState
     */
    public ConcreteFlyweight(Character intrinsicState) {
        this.intrinsicState = intrinsicState;
    }

    /**
     * 外蕴状态作为参数传入方法内，改变方法的行为，但是并不改变对象的内蕴状态。
     *
     * @param state
     */
    @Override
    public void operation(String state) {
        System.out.println("Intrinsic State = " + this.intrinsicState);
        // 如果有内蕴状态的话，必须为内蕴状态提供存储空间。
        System.out.println("Extrinsic State = " + state);
    }
}
